package org.hdax.dm.controller;

import org.hdax.dm.request.UserRequest;
import org.hdax.dm.request.VoVcodeRequest;
import org.hdax.dm.service.UserService;
import org.hdax.dm.vo.CommonResponse;
import org.hdax.dm.vo.entity.user.VoTokens;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping
public class LoginController {
    @Autowired
    private UserService userService;

    @PostMapping(path = "/p/login")
    @ResponseBody
    public CommonResponse<List<Object>> login(@RequestBody UserRequest userRequest) {
        return userService.login(userRequest.getPhone(), userRequest.getPassword());
    }


    /**
     * 用户登录获取验证码
     *
     * @param voVcodeRequest
     * @return
     */
    @PostMapping(path = "/p/getCode")
    @ResponseBody
    public CommonResponse<Object> getCode(@RequestBody VoVcodeRequest voVcodeRequest) {
        return userService.getCode(voVcodeRequest.getPhone());
    }

    /**
     * 验证码登录
     *
     * @param voVcodeRequest
     * @return
     */
    @PostMapping(path = "/p/codeLogin")
    @ResponseBody
    public CommonResponse<VoTokens> codeLogin(@RequestBody VoVcodeRequest voVcodeRequest) {
        return userService.codeLogin(voVcodeRequest);
    }

    /**
     * 用户注册获取验证码
     *
     * @param voVcodeRequest
     * @return
     */
    @PostMapping(path = "/p/enrollGetCode")
    @ResponseBody
    public CommonResponse<Object> enrollGetCode(@RequestBody VoVcodeRequest voVcodeRequest) {
        return userService.enrollGetCode(voVcodeRequest.getPhone());
    }

    /**
     * 验证码注册
     * @param voVcodeRequest
     * @return
     */
    @PostMapping(path = "/p/enrollLogin")
    @ResponseBody
    public CommonResponse<VoTokens> enrollLogin(@RequestBody VoVcodeRequest voVcodeRequest){
        return userService.enrollLogin(voVcodeRequest);
    }
}
